//
//  InvitePartnerViewController.m
//  NewPro
//
//  Created by RYX on 2018/11/9.
//  Copyright © 2018年 何荧红. All rights reserved.
//

#import "InvitePartnerViewController.h"
#import "NSData+Base64.h"
#import "MyCenterVC.h"
#import "NewHomeViewController.h"
#import "ShareStore.h"

@interface InvitePartnerViewController ()
{
    __weak IBOutlet UIImageView *im;
    __weak IBOutlet UILabel *la1;
    __weak IBOutlet UILabel *la2;
    __weak IBOutlet UILabel *la3;
}
@property (nonatomic, strong) PushView *ShareView;

@end

@implementation InvitePartnerViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self setNavBarWithTitle:@"邀请合伙人"];
    [self loadData];
    
    self.ShareView = [[PushView alloc]initWithShareView];
    [self.view addSubview:self.ShareView];

}

- (void)loadData{
    [[[ShareStore alloc]init] PostWithId:[UserDefaultsManager sharedInstance].user_id Success:^(NSDictionary * _Nonnull res) {
        if ([res[@"msg"] isEqualToString:@"success"]) {
            NSArray *arr = [res[@"data"][@"img"] componentsSeparatedByString:@","];
            NSData *data  = [[NSData alloc] initWithBase64EncodedString:arr[1]];
            NSDictionary *dic = @{@"img":data,@"customName":res[@"data"][@"custom"][@"realName"],@"phoneNumber":res[@"data"][@"custom"][@"phoneNumber"],@"recommendationCode":res[@"data"][@"custom"][@"recommendationCode"]};
            [self setdic:dic];
            self.ShareView.scanQdata = data;
            self.ShareView.weburl = res[@"data"][@"url"];
            self.ShareView.name = res[@"data"][@"maintitle"];
            self.ShareView.subtitle = res[@"data"][@"subtitle"];
        }
    } Failure:^(NSError * _Nonnull error) {
        [self showMBPError:[HttpTool handleError:error]];
    }];
}

- (IBAction)onInvateBtn:(UIButton *)sender {
    
    [self.ShareView ViewPush:YES];
}

- (void)setdic:(NSDictionary *)dic{

    if (dic) {
        
        im.image = [UIImage imageWithData:dic[@"img"]];
        la1.text = dic[@"recommendationCode"];
        la2.text = dic[@"customName"];
        la3.text = dic[@"phoneNumber"];
        
    }
}

- (void)back{
    
    UINavigationController *nav = [AppDelegate sharedAppDelegate].navigationViewController;
    
    NSMutableArray *viewControllers = [[NSMutableArray alloc]init];
    
    for (UIViewController *vc in [nav viewControllers]) {
        
        [viewControllers addObject:vc];
        
        if ([vc isKindOfClass:[MyCenterVC class]] || [vc isKindOfClass:[NewHomeViewController class]]) {
            
            break;
        }
    }
    
    [nav setViewControllers:viewControllers animated:YES];
}


@end
